﻿#include "PyFITKMaterialsFibers.h"
#include "FITKAcousticsPhysics.h"
#include "FITKAcousticsAbsMaterial.h"
#include "FITKAcousticsMaterialsFiber.h"

Acoustics::PyFITKMaterialsFibers::PyFITKMaterialsFibers(const QString & name) :
    Acoustics::PyFITKMaterialsBase(name)
{
}

bool Acoustics::PyFITKMaterialsFibers::setDensityResistivity(double density, double flowResistivity)
{
    if (!_material|| density<0|| flowResistivity<0)return false;

    FITKAcousticsMaterialsFiber *fiber = dynamic_cast<Acoustics::FITKAcousticsMaterialsFiber*>(_material);
    if (!fiber)return false;

    fiber->setDensity(density);
    fiber->setFlowResistivity(flowResistivity);
    return true;
}

bool Acoustics::PyFITKMaterialsFibers::setRigidLimpFrame(double porosity, double tortuosity, double viscousLength, double thermalLength)
{
    if (!_material)return false;
    if (porosity < 0 || tortuosity < 0 || viscousLength < 0 || thermalLength < 0)return false;

    FITKAcousticsMaterialsFiber *fiber = dynamic_cast<Acoustics::FITKAcousticsMaterialsFiber*>(_material);
    if (!fiber)return false;

    fiber->setPorosity(porosity);
    fiber->setTortuosity(tortuosity);
    fiber->setViscousLength(viscousLength);
    fiber->setThermalLength(thermalLength);
    return true;
}

bool Acoustics::PyFITKMaterialsFibers::createMaterial(const QString & name)
{
    if (name == "")return false;
    Acoustics::FITKAcousticsPhysics* phy = Acoustics::FITKAcousticsPhysics::GetAcousticsPhysicsFromFrame();
    if (phy == nullptr) return false;
    Acoustics::FITKAcousticsMaterialManager* matMgr = phy->getMaterialManager();
    if (matMgr == nullptr) return false;
    if (matMgr->getDataByName(name))return false;

    FITKAcousticsMaterialsFiber * fiber = new FITKAcousticsMaterialsFiber();
    fiber->setDataObjectName(name);
    _material = fiber;
    matMgr->appendDataObj(_material);

    return true;
}
